package org.example.musicserver.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.example.musicserver.common.Result;
import org.example.musicserver.entity.Admin;
import org.example.musicserver.mapper.AdminMapper;
import org.example.musicserver.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public Result verityPasswd(String name,String password, HttpSession session) {
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        queryWrapper.eq("password",password);
        if (adminMapper.selectCount(queryWrapper) > 0) {
            session.setAttribute("name", name);
            return Result.success("登录成功");
        } else {
            return Result.error("用户名或密码错误");
        }
    }
}
